package invalidcomponentgeneralization;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import invalidcomponentgeneralization.InvalidComponentGeneralizationMatch;
import invalidcomponentgeneralization.InvalidComponentGeneralizationMatcherFactory;
import invalidcomponentgeneralization.InvalidComponentGeneralizationMatcher;

public class InvalidComponentGeneralizationConstraint extends Constraint<InvalidComponentGeneralizationMatch> {

	private InvalidComponentGeneralizationMatcherFactory matcherFactory;

	public InvalidComponentGeneralizationConstraint() {
		matcherFactory = new InvalidComponentGeneralizationMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "$component1.name$ rest component and $component2.name$ business component should not be in the same generalization path!";
	}

	@Override
	public EObject getLocationObject(InvalidComponentGeneralizationMatch signature) {
		Object location = signature.get("component1");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<InvalidComponentGeneralizationMatch, InvalidComponentGeneralizationMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
